package com.maishi.programmer.jainzhioffer;

import java.util.Arrays;

/**
 * Created by brossdong on 2018/4/16.
 * 随机抽5张牌 扑克牌顺子
 * 4个大小王 ==> 表示0
 */
public class TestProblem61 {

    /**
     * @param numbers
     * @return
     * 先排序,然后统计0的个数,计算空缺的总数与0的对比
     */
    public static boolean isContinuous(int [] numbers) {

        if (numbers.length != 5 || numbers == null) return false;
        //排序
        Arrays.sort(numbers);
        //统计0的个数
        int countZero = 0;
        for (int i = 0;i < numbers.length;i++) {
            if (numbers[i] == 0) {
                countZero++;
            }
        }
        System.out.println(countZero);
        //计算空缺的总数与0的对比
        int index1 = countZero;
        int index2 = index1 + 1;
        int numOfDif = 0;
        while (index2 < numbers.length) {
            if (numbers[index1] == numbers[index2]) {
                return false;
            }
            numOfDif += numbers[index2] - numbers[index1] - 1;
            index1 = index2;
            index2++;
        }
        return (countZero < numOfDif) ? false : true;
    }

    public static void main(String[] args) {
        boolean continuous = isContinuous(new int[]{1,3,2,6,4});
        System.out.println(continuous);
    }

}
